#include "stdafx.h"
#include "PropertyDescription.h"
#include "PropertyTemplateId.h"
#include <utility/Streams.h>

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //_DEBUG
#endif //WIND32

namespace serika
{
	namespace dq
	{
		PropertyDescription::PropertyDescription()
		{
		}

		PropertyDescription::~PropertyDescription()
		{
		}

		// static
		void PropertyDescription::GetDescription(int templateId, const ut::String& templateDescription, int reserved1, int reserved2, int reserved3, const ut::String& reserved4, ut::String& description)
		{
			description = templateDescription;
			ReplaceString(description, _T("$(r1)"), reserved1);
			ReplaceString(description, _T("$(r2)"), reserved2);
			ReplaceString(description, _T("$(r3)"), reserved3);
			ReplaceString(description, _T("$(r4)"), reserved4);
			//switch (templateId)
			//{
			//case PropertyTemplateId::Ability:
			//	description = templateDescription;
			//	ReplaceString(description, _T("$(r2)"), reserved2);
			//	ReplaceString(description, _T("$(r4)"), reserved4);
			//	break;

			//case PropertyTemplateId::AttackAttribute:
			//	description = templateDescription;
			//	ReplaceString(description, _T("$(r4)"), reserved4);
			//	break;

			//case PropertyTemplateId::AttackStatus:
			//	description = templateDescription;
			//	ReplaceString(description, _T("$(r4)"), reserved4);
			//	break;

			//case PropertyTemplateId::AttackMonster:
			//	description = templateDescription;
			//	ReplaceString(description, _T("$(r2)"), reserved2);
			//	ReplaceString(description, _T("$(r4)"), reserved4);
			//	break;
			//}
		}

		// static
		inline void PropertyDescription::ReplaceString(ut::String& str, const ut::String& find, const ut::String& replacement)
		{
			size_t index = str.find(find);
			while (index != std::string::npos)
			{
				str.replace(index, find.size(), replacement);
				index = str.find(find, index+replacement.size());
			}
		}

		// static
		inline void PropertyDescription::ReplaceString(ut::String& str, const ut::String& find, int replacement)
		{
			ut::Sstream ss;
			ss << replacement;
			PropertyDescription::ReplaceString(str, find, ss.str());
		}
	}
}
